package com.service.bean.signal;

import java.sql.Timestamp;
import java.text.MessageFormat;
import java.util.Date;

import com.service.calculate.hookArmCase.HookArmCaseIDCreator;

/**
 * 勾臂车箱体定位信息
 * @author lj
 *
 */
public class GpsHookArmCaseSignal implements Comparable<GpsHookArmCaseSignal> {
	
	public GpsHookArmCaseSignal() {
		this.signalId = HookArmCaseIDCreator.getSignalId();
	}
	/**
	 * 勾臂车箱体定位信息ID
	 */
	public String signalId;
	/**
	 * 定位终端编号
	 */
	public String gpsNo;
	/**
	 * 定位时间
	 */
	public Date gpsTime;
	/**
	 * 卫星定位经度
	 */
	public double lng;
	/**
	 * 卫星定位纬度
	 */
	public double lat;
	/**
	 * GPS定位是否有效</br>0： 定位无效</br>1: 定位有效
	 */
	public int gpsStatus;
	/**
	 * 百度经度
	 */
	public double baiduLng;
	/**
	 * 百度纬度
	 */
	public double baiduLat;
	/**
	 * 百度地址(预留)
	 */
	public String baiduLocation;
	/**
	 * 公司代码
	 */
	public String companyCode;
	/**
	 * 预留
	 */
	public int equipmentType;
	/**
	 * 勾臂车箱体ID
	 */
	public String caseId;
	/**
	 * 箱体名称(不插入数据库, 仅提供给前端使用)
	 */
	public String caseName;
	/**
	 * 报警位</br>0: 箱体未满溢</br>1: 箱体已满溢
	 */
	public int isGarbageFull;
	/**
	 * 数据类型 0：历史数据 1：实时数据
	 */
	public int dataTypes;
	/**
	* 电源状态
	*/
	public int batteryStatus;

	public Object[] getAll() {
		Object[] arrs = new Object[14];
		arrs[0] = "'" + signalId + "'";
		arrs[1] = "'" + gpsNo + "'";
		arrs[2] = gpsTime == null ? gpsTime : "'" + new Timestamp(gpsTime.getTime()) + "'";
		arrs[3] = String.valueOf(lng);
		arrs[4] = String.valueOf(lat);
		arrs[5] = gpsStatus;
		arrs[6] = equipmentType;
		arrs[7] = String.valueOf(baiduLng);
		arrs[8] = String.valueOf(baiduLat);
		arrs[9] = baiduLocation == null ? baiduLocation : "'" + baiduLocation + "'";
		arrs[10] = "'" + companyCode + "'";
		arrs[11] = "'" + caseId + "'";
		arrs[12] = isGarbageFull;
		arrs[13] = "'" + caseName + "'";
		return arrs;
	}

	@Override
	public String toString() {
		StringBuffer buffer = new StringBuffer();
		buffer.append("\"GPSNO\":{0},");
		buffer.append("\"GPSTime\":{1},");
		buffer.append("\"GPSStatus\":{2},");
		buffer.append("\"BaiduLng\":{3},");
		buffer.append("\"BaiduLat\":{4},");
		buffer.append("\"CaseId\":{5},");
		buffer.append("\"IsGarbageFull\":{6},");
		buffer.append("\"CaseName\":{7}");
		return MessageFormat.format(buffer.toString(), getAllForJson());
	}

	private Object[] getAllForJson() {
		Object[] arrs = new Object[8];
		arrs[0] = "\"" + gpsNo + "\"";
		arrs[1] = gpsTime == null ? gpsTime : "\"" + new Timestamp(gpsTime.getTime()) + "\"";
		arrs[2] = "\"" + gpsStatus + "\"";
		arrs[3] = "\"" + baiduLng + "\"";
		arrs[4] = "\"" + baiduLat + "\"";
		arrs[5] = "\"" + caseId + "\"";
		arrs[6] = "\"" + isGarbageFull + "\"";
		arrs[7] = "\"" + caseName + "\"";
		return arrs;
	}
	
	@Override
	public int compareTo(GpsHookArmCaseSignal s) {
		return gpsTime.after(s.gpsTime) ? 1 : -1;
	}
	
}
